<template>
  <div class="app-container">
    <div class="header">
      <div class="word">
        <div class="w1">
          病虫害预览系统
        </div>
        <div class="w2">
          在病虫害预览系统中你可以录入的肉桂病症，实现对肉桂病虫害的增添删除，而且你还可以通过病虫害搜索功能实现对病虫害的搜索，从而对指定病虫害的进行修改与增添治疗方法等操作。
        </div>
        <div class="w2">
          病虫害预览系统是病虫害防治中重要的一环,它可以帮助我们添加，更改肉桂病症的病虫害信息，为肉桂的防治做准备。
        </div>
      </div>
      <img class="imgDri" src="../static/580c1c6fba284_610.jpg">
    </div>
    <div class="index">
      <div class="searchHead">
        <div class="headSearch">
          病虫害名称:<el-input v-model="deName" style="width: 200px;" placeholder="请输入内容" />
        </div>
        <div class="headSearch">
          病虫害部位: <el-select v-model="vaPlace" placeholder="请选择">
            <el-option v-for="item in dePlace" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </div>
        <div class="headSearch">
          病虫害类型: <el-select v-model="vaType" placeholder="请选择">
            <el-option v-for="item in deType" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </div>
        <div class="headSearch">
          <el-button type="primary" plain @click="dialogFormVisible = true">添加</el-button>
          <el-button type="info" plain @click="searchMeasure">查询</el-button>
        </div>
      </div>

      <el-dialog title="病害信息添加" :visible.sync="dialogFormVisible">
        <el-form class="form">
          <el-form-item class="item" label="" :label-width="formLabelWidth">
            <div>病虫害名称</div>
            <el-input v-model="addMes.scientificName" class="in" autocomplete="off" />
          </el-form-item>
          <el-form-item class="item" label="" :label-width="formLabelWidth">
            <div>病虫害俗名</div>
            <el-input v-model="addMes.commonName" class="in" autocomplete="off" />
          </el-form-item>
          <el-form-item class="item" label="" :label-width="formLabelWidth">
            <div>病虫害英文名</div>
            <el-input v-model="addMes.englishName" class="in" autocomplete="off" />
          </el-form-item>
          <el-form-item class="item" label="" :label-width="formLabelWidth">
            <div>出现季节</div>
            <el-input v-model="addMes.occurSeason" class="in" autocomplete="off" />
          </el-form-item>
          <el-form-item class="item" label="" :label-width="formLabelWidth">
            <div>病虫害图片（仅支持链接）</div>
            <el-input v-model="addMes.picture" class="in" autocomplete="off" />
          </el-form-item>
          <el-form-item class="item" label="" :label-width="formLabelWidth">
            <div>病虫害主要分布情况（仅支持链接）</div>
            <el-input v-model="addMes.occurLocationPicture" class="in" autocomplete="off" />
          </el-form-item>
          <div class="sel">
            <el-select v-model="addMes.type" lable="虫害类型" class="sel2" placeholder="请选择病虫害类型">
              <el-option label="虫害" value="虫害" />
              <el-option label="病害" value="病害" />
              <el-option label="生理病害" value="生理病害" />
              <el-option label="草害" value="草害" />
              <el-option label="天敌" value="天敌" />
            </el-select>
          </div>
          <div class="sel">
            <el-select v-model="addMes.diseasePlace" label="虫害部位" class="sel2" placeholder="请选择病虫害部位">
              <el-option label="根" value="根" />
              <el-option label="茎" value="茎" />
              <el-option label="叶" value="叶" />
              <el-option label="树干" value="树干" />
              <el-option label="枝" value="枝" />
              <el-option label="果" value="果" />
            </el-select>
          </div>
          <div class="a">
            <div class="b">病虫害简介</div>
          </div>
          <div class="a">
            <el-input
              v-model="addMes.briefIntro"
              class="textInput"
              type="textarea"
              :rows="3"
              :autosize="{ minRows: 3, maxRows: 3 }"
              placeholder="请输入病虫害简介"
            />
          </div>
          <div class="a">
            <div class="b">主要症状</div>
          </div>
          <div class="a">
            <el-input
              v-model="addMes.mainSymptom"
              class="textInput"
              type="textarea"
              :rows="3"
              :autosize="{ minRows: 3, maxRows: 3 }"
              placeholder="请输入主要症状"
            />
          </div>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="addDri()">确 定</el-button>
        </div>
      </el-dialog>

      <el-table :data="mes" type="" style="width: 100%">
        <el-table-column prop="scientificName" label="名称" width="180" />
        <el-table-column prop="commonName" label="俗名" width="180" />
        <el-table-column prop="diseasePlace" label="病虫害部位" width="180" />
        <el-table-column prop="type" label="类型" width="180" />
        <el-table-column prop="mainSymptom" label="主要症状" />
        <el-table-column prop="briefIntro" label="简介" />
        <el-table-column fixed="right" label="操作" width="150">
          <template slot-scope="scope">
            <div class="option">
              <el-button type="text" @click="mes[scope.$index].isShowAdd = true">添加处方</el-button>
              <el-button type="text" @click="meaSureChan(scope.$index)">修改处方</el-button>
              <el-button type="text" class="p" @click="mes[scope.$index].isShow = true">修改状态</el-button>
              <el-button type="text" style="color:red" @click="mes[scope.$index].isShowDel = true">删除</el-button>
            </div>
            <el-dialog :modal-append-to-body="false" title="提示" :visible.sync="mes[scope.$index].isShowDel" width="30%">
              <span>确认要删除此条信息吗？</span>
              <span slot="footer" class="dialog-footer">
                <el-button @click="mes[scope.$index].isShowDel = false">取 消</el-button>
                <el-button type="primary" @click="driveDel(scope.$index)">确 定</el-button>
              </span>
            </el-dialog>

            <el-dialog :modal-append-to-body="false" title="添加处方" :visible.sync="mes[scope.$index].isShowAdd" width="30%">
              <div class="form">
                <div>
                  <el-input
                    v-model="meaSure"
                    class="textInput"
                    type="textarea"
                    :rows="3"
                    :autosize="{ minRows: 3, maxRows: 3 }"
                    placeholder="请输入防治处方"
                  />
                </div>
              </div>
              <span slot="footer" class="dialog-footer">
                <el-button @click="mes[scope.$index].isShowAdd = false">取 消</el-button>
                <el-button type="primary" @click="meaSureAdd(scope.$index)">确 定</el-button>
              </span>
            </el-dialog>

            <el-dialog :modal-append-to-body="false" title="添加处方" :visible.sync="mes[scope.$index].isShowCh" width="30%">

              <div class="form">
                <template v-for="(item, i) in meaSureMes">
                  <div :key="i">
                    <div class="p">处方{{ i + 1 }}</div>
                    <el-input
                      v-model="item.measure"
                      class="textInput"
                      type="textarea"
                      :rows="3"
                      :autosize="{ minRows: 3, maxRows: 3 }"
                      placeholder="请输入防治处方"
                    />
                  </div>
                  <div class="l">
                    <div slot="footer" class="ll">
                      <el-button type="info" @click="meaSure111(i)">确 定</el-button>
                      <el-button type="info" @click="meaSureD(i,scope.$index)">删除</el-button>

                    </div>
                  </div>
                </template>
              </div>
              <span slot="footer" class="dialog-footer">
                <el-button @click="mes[scope.$index].isShowCh = false">取 消</el-button>
              </span>
            </el-dialog>

            <el-dialog :modal-append-to-body="false" title="修改信息" :visible.sync="mes[scope.$index].isShow">
              <el-form class="form">
                <el-form-item class="item" label="" :label-width="formLabelWidth">
                  <div>病虫害名称</div>
                  <el-input v-model="mes[scope.$index].scientificName" class="in" autocomplete="off" />
                </el-form-item>
                <el-form-item class="item" label="" :label-width="formLabelWidth">
                  <div>病虫害俗名</div>
                  <el-input v-model="mes[scope.$index].commonName" class="in" autocomplete="off" />
                </el-form-item>
                <el-form-item class="item" label="" :label-width="formLabelWidth">
                  <div>病虫害英文名</div>
                  <el-input v-model="mes[scope.$index].englishName" class="in" autocomplete="off" />
                </el-form-item>
                <el-form-item class="item" label="" :label-width="formLabelWidth">
                  <div>出现季节</div>
                  <el-input v-model="mes[scope.$index].occurSeason" class="in" autocomplete="off" />
                </el-form-item>
                <el-form-item class="item" label="" :label-width="formLabelWidth">
                  <div>病虫害图片（仅支持链接）</div>
                  <el-input v-model="mes[scope.$index].picture" class="in" autocomplete="off" />
                </el-form-item>
                <el-form-item class="item" label="" :label-width="formLabelWidth">
                  <div>病虫害主要分布情况（仅支持链接）</div>
                  <el-input v-model="mes[scope.$index].occurLocationPicture" class="in" autocomplete="off" />
                </el-form-item>
                <div class="sel">
                  <el-select v-model="mes[scope.$index].type" lable="虫害类型" class="sel2" placeholder="请选择病虫害类型">
                    <el-option label="虫害" value="虫害" />
                    <el-option label="病害" value="病害" />
                    <el-option label="生理病害" value="生理病害" />
                    <el-option label="草害" value="草害" />
                    <el-option label="天敌" value="天敌" />
                  </el-select>
                </div>
                <div class="sel yy">
                  <el-select v-model="mes[scope.$index].diseasePlace" label="虫害部位" class="sel2" placeholder="请选择病虫害部位">
                    <el-option label="根" value="根" />
                    <el-option label="茎" value="茎" />
                    <el-option label="叶" value="叶" />
                    <el-option label="树干" value="树干" />
                    <el-option label="枝" value="枝" />
                    <el-option label="果" value="果" />
                  </el-select>
                </div>
                <div class="a">
                  <div class="b">病虫害简介</div>
                </div>
                <div class="a">
                  <el-input
                    v-model="mes[scope.$index].briefIntro"
                    class="textInput"
                    type="textarea"
                    :rows="3"
                    :autosize="{ minRows: 3, maxRows: 3 }"
                    placeholder="请输入病虫害简介"
                  />
                </div>
                <div class="a">
                  <div class="b">主要症状</div>
                </div>
                <div class="a">
                  <el-input
                    v-model="mes[scope.$index].mainSymptom"
                    class="textInput"
                    type="textarea"
                    :rows="3"
                    :autosize="{ minRows: 3, maxRows: 3 }"
                    placeholder="请输入主要症状"
                  />
                </div>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="mes[scope.$index].isShow = false">取 消</el-button>
                <el-button type="primary" @click="changeDriver(scope.$index)">确 定</el-button>
              </div>
            </el-dialog>
          </template>
        </el-table-column>
      </el-table>
      <div class="page">
        <el-pagination
          :page-size="5"
          layout="prev, pager, next, jumper"
          :total="pageSize"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import request from '../../../utils/request'
export default {
  name: 'DiseasePreview',
  data() {
    return {
      mes: [],
      dialogTableVisible: false,
      formLabelWidth: '120px',
      vaPlace: '',
      vaType: '',
      deName: '',
      meaSure: '',
      addMes: {
        'briefIntro': '',
        'commonName': '',
        'diseaseId': '',
        'diseasePlace': '',
        'englishName': '',
        'gmtCreate': '',
        'gmtModified': '',
        'isDelete': '',
        'mainSymptom': '',
        'occurLocationPicture': '',
        'occurSeason': '',
        'picture': '',
        'scientificName': '',
        'type': '',
        'vedioLink': ''
      },
      meaSureMes: [],
      dialogFormVisible: false,
      pageSize: null,
      select: '',
      searchInf: '',
      input3: '',
      deType: [{
        value: '虫害',
        label: '虫害'
      }, {
        value: '病害',
        label: '病害'
      }, {
        value: '生理病害',
        label: '生理病害'
      }, {
        value: '草害',
        label: '草害'
      }, {
        value: '天敌',
        label: '天敌'
      }],
      vType: '',
      dePlace: [{
        value: '根',
        label: '根'
      }, {
        value: '茎',
        label: '茎'
      }, {
        value: '叶',
        label: '叶'
      }, {
        value: '树干',
        label: '树干'
      }, {
        value: '枝',
        label: '枝'
      }, {
        value: '果',
        label: '果'
      }
      ],
      vPlace: ''
    }
  },
  async mounted() {
    this.getDrive()
  },
  methods: {
    async getDrive() {
      await request({
        method: 'get',
        url: '/pad/characteristic/pageCharacter/1/5'
      }).then((response) => {
        console.log(response)
        this.mes = response.data.records
        for (let i = 0; i < this.mes.length; i++) {
          this.$set(this.mes[i], 'isShow', false)
          this.$set(this.mes[i], 'isShowDel', false)
          this.$set(this.mes[i], 'isShowAdd', false)
          this.$set(this.mes[i], 'isShowCh', false)
        }
        this.pageSize = response.data.total * 1
        console.log(this.pageSize)
      })
    },
    async changeDriver(index) {
      console.log(this.mes[index])
      const driverLogistics = {
        'briefIntro': this.mes[index].briefIntro,
        'commonName': this.mes[index].commonName,
        'diseaseId': this.mes[index].diseaseId,
        'diseasePlace': this.mes[index].diseasePlace,
        'englishName': this.mes[index].englishName,
        'gmtCreate': this.mes[index].gmtCreate,
        'gmtModified': this.mes[index].gmtModified,
        'isDelete': this.mes[index].isDelete,
        'mainSymptom': this.mes[index].mainSymptom,
        'occurLocationPicture': this.mes[index].occurLocationPicture,
        'occurSeason': this.mes[index].occurSeason,
        'picture': this.mes[index].picture,
        'scientificName': this.mes[index].scientificName,
        'type': this.mes[index].type,
        'vedioLink': this.mes[index].vedioLink
      }
      console.log(driverLogistics)
      await request({
        method: 'post',
        url: '/pad/characteristic/updateCharacter',
        data: driverLogistics
      }).then(response => {
        console.log(response)
        if (response.statusCode == 20000) {
          this.dialogFormVisible = false
          this.addMes = {}
          this.$message({
            message: '添加成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '发生错误，添加失败',
            type: 'warning'
          })
        }
      })
      this.getDrive()
      this.mes[index].isShow = false
    },
    async driveDel(index) {
      await request({
        method: 'delete',
        url: '/pad/characteristic/delete/' + this.mes[index].diseaseId
      }).then(response => {
        console.log(response)
        if (response.statusCode == 20000) {
          this.dialogFormVisible = false
          this.addMes = {}
          this.$message({
            message: '删除成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '发生错误，添加失败',
            type: 'warning'
          })
        }
      })
      this.getDrive()
      this.mes[index].isShowDel = false
    },
    async addDri() {
      request({
        method: 'post',
        url: '/pad/characteristic/addCharacter',
        data: this.addMes
      }).then(response => {
        console.log(response)
        if (response.statusCode == 20000) {
          this.dialogFormVisible = false
          this.addMes = {}
          this.getDrive()
          this.$message({
            message: '添加成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '发生错误，添加失败',
            type: 'warning'
          })
        }
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      request({
        method: 'get',
        url: '/pad/characteristic/pageCharacter/' + val + '/5'
      }).then((response) => {
        console.log(response)
        this.mes = response.data.records
        for (let i = 0; i < this.mes.length; i++) {
          this.$set(this.mes[i], 'isShow', false)
          this.$set(this.mes[i], 'isShowDel', false)
          this.$set(this.mes[i], 'isShowAdd', false)
          this.$set(this.mes[i], 'isShowCh', false)
        }
        this.pageSize = response.data.total * 1
      })
    },
    searchMes() {
      if (this.select == 'id') {
        const data = {
          id: this.input3
        }
        request({
          url: '/zk/driverLogistics/get',
          method: 'post',
          data: data
        }).then(response => {
          if (response.statusCode == 20000) {
            this.$message({
              message: '查询成功',
              type: 'success'
            })
            console.log(response)
            this.mes = response.data
            for (let i = 0; i < this.mes.length; i++) {
              this.$set(this.mes[i], 'isShow', false)
              this.$set(this.mes[i], 'isShowDel', false)
            }
            this.pageSize = response.data.length
          } else {
            this.$message({
              message: '查无此人，查询失败',
              type: 'warning'
            })
          }
        })
      } else if (this.select == 'driverName') {
        const data = {
          driverName: this.input3
        }
        request({
          url: '/zk/driverLogistics/get',
          method: 'post',
          data: data
        }).then(response => {
          if (response.statusCode == 20000) {
            this.$message({
              message: '查询成功',
              type: 'success'
            })
            console.log(response)
            this.mes = response.data
            for (let i = 0; i < this.mes.length; i++) {
              this.$set(this.mes[i], 'isShow', false)
              this.$set(this.mes[i], 'isShowDel', false)
            }
            this.pageSize = response.data.length
          } else {
            this.$message({
              message: '查无此人，查询失败',
              type: 'warning'
            })
          }
        })
      } else if (this.select == 'drivingLicenseNumber') {
        const data = {
          drivingLicenseNumber: this.input3
        }
        request({
          url: '/zk/driverLogistics/get',
          method: 'post',
          data: data
        }).then(response => {
          if (response.statusCode == 20000) {
            this.$message({
              message: '查询成功',
              type: 'success'
            })
            console.log(response)
            this.mes = response.data
            for (let i = 0; i < this.mes.length; i++) {
              this.$set(this.mes[i], 'isShow', false)
              this.$set(this.mes[i], 'isShowDel', false)
            }
            this.pageSize = response.data.length
          } else {
            this.$message({
              message: '查无此人，查询失败',
              type: 'warning'
            })
          }
        })
      }
    },
    async meaSureD(i, ax) {
      console.log(this.meaSureMes)
      await request({
        url: '/pad/measure/deleteMea/' + this.meaSureMes[i].measureId,
        method: 'delete'
      }).then(response => {
        if (response.statusCode == 20000) {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.meaSureGet(ax)
        } else {
          this.$message({
            message: '发生错误，删除失败',
            type: 'warning'
          })
        }
      })
    },
    async meaSureAdd(index) {
      const data = {
        'gmtCreate': '',
        'gmtModified': '',
        'measure': this.meaSure,
        'measureId': ''
      }
      if (this.meaSure == '') {
        this.$message({
          message: '请勿空白提交',
          type: 'warning'
        })
      } else {
        await request({
          url: '/pad/measure/addMea/' + this.mes[index].diseaseId,
          method: 'post',
          data: data
        }).then(response => {
          if (response.statusCode == 20000) {
            this.$message({
              message: '添加成功',
              type: 'success'
            })
            this.meaSure = ''
            this.mes[index].isShowAdd = false
          } else {
            this.$message({
              message: '发生错误，添加失败',
              type: 'warning'
            })
          }
        })
      }
    },
    async meaSureGet(index) {
      await request({
        url: '/pad/measure/getByCharacterId/' + this.mes[index].diseaseId,
        method: 'get'
      }).then(response => {
        if (response.statusCode == 20000) {
          this.meaSureMes = response.data
        } else {
          this.$message({
            message: '发生错误，打开失败',
            type: 'warning'
          })
        }
      })
    },
    meaSureChan(index) {
      this.meaSureGet(index)
      this.mes[index].isShowCh = true
    },
    async meaSure111(index) {
      const data = {
        'gmtCreate': this.meaSureMes[index].gmtCreate,
        'gmtModified': this.meaSureMes[index].gmtModified,
        'measure': this.meaSureMes[index].measure,
        'measureId': this.meaSureMes[index].measureId
      }
      console.log(data)
      console.log(index)
      await request({
        url: '/pad/measure/updateMea',
        method: 'post',
        data: data
      }).then(response => {
        if (response.statusCode == 20000) {
          console.log(response)
          this.$message({
            message: '修改成功',
            type: 'success'
          })
        } else {
          this.$message({
            message: '发生错误，修改失败',
            type: 'warning'
          })
        }
      })
    },
    async searchMeasure() {
      const data = {
        'diseasePlace': this.vaPlace,
        'scientificName': this.deName,
        'type': this.vaType
      }
      console.log(data)
      await request({
        url: '/pad/characteristic/pageCharacterCondition/1/100',
        method: 'post',
        data: data
      }).then(response => {
        if (response.statusCode == 20000) {
          console.log(response)
          this.mes = response.data.records
          if (response.data.total == '0') {
            this.$message({
              message: '无此种病虫害数据，请前去添加',
              type: 'warning'
            })
          }
          for (let i = 0; i < this.mes.length; i++) {
            this.$set(this.mes[i], 'isShow', false)
            this.$set(this.mes[i], 'isShowDel', false)
            this.$set(this.mes[i], 'isShowAdd', false)
            this.$set(this.mes[i], 'isShowCh', false)
          }
          this.pageSize = response.data.total * 1
          if (response.data.total != '0') {
            this.$message({
              message: '查询成功',
              type: 'success'
            })
          }
        } else {
          this.$message({
            message: '发生错误，修改失败',
            type: 'warning'
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.b {
  margin-left: 100px;
  margin-top: 10px;
}

.header {
  width: 100%;
  height: 350px;
  // border: 1px solid black;
  display: flex;
  margin-bottom: 20px;
  justify-content: space-between;
}

.option {
  display: flex;
  width: 140;
  flex-wrap: wrap;
  justify-content: space-around;
  align-items: center;
}

.form {
  display: flex;
  flex-wrap: wrap;
  // border: 1px solid black;
  // justify-content: space-around;
}

.in {
  width: 250px;
}

.sel {
  width: 360px;
  display: flex;
  height: 50px;
  // border: 1px solid black;
  // border: 1px solid black;
  justify-content: flex-end;
  align-content: center;
  // border: 1px solid black;
}

.sel2 {
  width: 240px;
  // border: 1px solid black;

}

.textInput {
  margin-left: 100px;
  margin-top: 10px;
}

.page {
  width: 100%;
  display: flex;
  justify-content: right;
}

.sum {
  display: flex;
  justify-content: center;
  align-items: center;
}

.p {
  margin-left: -10px;
}

.imgDri {
  height: 300px;
  width: 400px;
}

.w1 {
  height: 80px;
  font-size: 25px;
  font-weight: 350;
}

.textSum {
  display: flex;
  justify-content: center;
  align-items: center;
}

.w2 {
  height: 50px;
  font-size: 15px;
  font-weight: 250;
}

.yy {
  margin-left: 10px;
}

.a {
  // border: 1px solid black;
  width: 700px;
}

.searchHead {
  display: flex;
  justify-content: space-around;
  background-color: #f3f3f3;
  height: 80px;
  align-items: center;
  border-radius: 20px;
  margin-bottom: 10px;
}

.searchIuput {
  width: 350px;
  margin-left: 100px;
}

.sel3 {
  width: 100px;
}

.p {}

.l {
  margin-top: 10px;
  display: flex;
  width: 450px;
  // border: 1px solid black;
  justify-content: flex-end;
}
</style>
